<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>新品有戏商家合作平台</title>
    <script src="__JS__/jquery.js"></script>
    <link href="__CSS__/boot.css" rel="stylesheet">
    <link href="__STATIC__/layui/css/layui.css" rel="stylesheet">
    <script src="__JS__/layer/layer.js"></script>
    <script src="__STATIC__/layui/layui.js"></script>
    <style>
        tr td{
            text-align: center;
        }
    </style>
</head>
<body>
{include file="base/header" /}
<div style="float: right; margin-top: 5px;margin-bottom: 5px" class="box-title ">
    <form class="form-inline" action="{:url('business/order/index')}" method="get">
        <input type="text" placeholder="合作店名称" name="title" value="<?php if(isset($title)) echo $title ?>" class="form-control" id="exampleInputEmail3" >
        <input type="submit"  class="btn btn-default" value="搜索"/>
        <input type="button" onclick="res()" value="全部显示" class="btn btn-default"/>
    </form>
</div>
<table class="layui-table" id="test_table">
    <thead>
    <tr>
        <td>合作店名称</td>
        <td>操作</td>
    </tr>
    </thead>
    <tbody>
    {foreach $result as $val}
        <tr>
            <td style="display: none;">{$val.id}</td>
            <td>{$val.address}</td>
            <td>
                <button type="button" onclick="goods({$val.id})" class="btn btn-primary btn-xs">查看结算记录</button>
            </td>
        </tr>
    {/foreach}
    </tbody>

</table>
{$result->render()}
</body>
<script>
    //全部显示
    function res() {
        window.location.href = "{:url('business/order/index')}";
    }
    //详情
    function goods(id) {
        window.location.href = "{:url('business/order/goods')}?sid="+id;
    }
    //申请结算
    function settlement() {
        var checkbox = $("input[name=check]:checked").val();
        if(!checkbox){
            layer.alert('请选择需要申请结算的订单');
            return ;
        }
        var all = [];

        var rows = document.getElementById("test_table").rows;
        var check = document.getElementsByName("check");
        var  table = document.getElementById("test_table");
        for(var i=0;i<check.length;i++)
        {
            var single = [];
            if(check[i].checked){
                var row = check[i].parentElement.parentElement.rowIndex;
                var id = (rows[row].cells[1].innerHTML);
                var settnumber = (rows[row].cells[3].innerHTML) - (rows[row].cells[5].innerHTML);
                single.push(id);
                single.push(settnumber);
            }
            all.push(single);
        }

        $.ajax({
            url:"{:url('business/order/settlement')}",
            data:"data="+JSON.stringify(all),
            type:"post",
            dataType:"json",
            success:function (res) {
                if(res.error){
                    layer.alert(res.error);
                }
                if(res.success){
                    layer.alert(res.success,{bnt:['确定']},function () {
                        window.location.reload();
                    })
                }
            }
        });
    }
</script>
</html>